package com.example.xcsubsystem.repository;

import com.example.xcsubsystem.entity.ResourceEntity;
import com.example.xcsubsystem.vo.ServiceStatusVO;
import jakarta.transaction.Transactional;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

/**
 * 2024/9/28
 *
 * @author fengyu
 */
public interface ResourceRepository extends JpaRepository<ResourceEntity, Long> {
    @Transactional
    @Query("update ResourceEntity r set r.remoteId=?1 where r.id=?2")
    @Modifying
    int updateRemoteId(String remoteId, long id);

    @Query("select new com.example.xcsubsystem.vo.ServiceStatusVO(r.remoteId, r.status) from ResourceEntity r where r.remoteId is not null ")
    List<ServiceStatusVO> findAllStatus();
}
